<?php
class BannerController extends AppController {
    var $components = array ('Upload', 'Thumb');   

    public function beforeFilter(){
        
		parent::beforeFilter();
		// tutte le azioni di questo controller possono essere eseguite
    }
    
    
    
    public function index(){
       $this->layout="admin";
       $banner_list = $this->Banner->find("all");
       $this->set("banners",$banner_list);
    }
    
    public function edit($id){
	   $this->layout="admin";
       $bm = $this->Banner->read(null,$id);
       $this->set("banner",$bm);
    }
    
    public function add(){
	    $this->layout="admin";
        $banner = $this->Banner->create();
        $this->set("banner",$banner); 
    }
    
    public function save($id=null){
        //pr($_FILES);die;
        $ds = $this->Banner->getDataSource();
        $ds->begin();
        // salvo i file su attach se mi vengono passati dal form
        $filesuploaded = $this->Upload->execute();
        // --------------------------------------------------------
        !empty( $filesuploaded ) && $this->request->data["Banner"]["banner_id"]=$filesuploaded[0]['id'];
        $this->Banner->set($this->request->data);
        
        if($this->Banner->save())$ds->commit();       
        
        $this->Session->setFlash("Banner salvato con successo");
        $this->redirect("/Banner/edit/".$this->Banner->id);
        
    }
    
    public function delete($value)
    {
        //$this->Bookmaker->unbindModel(array('hasMany' => array('BookmakerLang')));
        $this->Banner->read(null,$value);
        $this->Banner->delete();  
              
        $this->Session->setFlash("Banner eliminato con successo");
        $this->redirect("/Banner/index");
    }

}

?>